package sysAuth

import initConfig.SysInitData

class SysRoleRela {

    SysRoles role;
    String roleType;
    Long dataId;
    static constraints = {
        role(nullable: false,blank: false )
        dataId(nullable: false,blank: false)
        roleType(nullable: false,blank: false)
    }
    static mapping = {
        version false
    }


    static init(){
        if(SysRoleRela.count ==0){
            def adminRole = SysRoles.findByRoleNo(SysInitData.ADMIN_FUNC_ROLE)
            SysRoles.list().each {
                new SysRoleRela(role: adminRole,dataId: it.id,roleType:SysInitData.FUNC_ROLE ).save(flush: true)
            }

            def testRole = SysRoles.findByRoleNoAndRoleType(SysInitData.TEST_NAME,SysInitData.FUNC_ROLE)
            SysFunctions.findAllByFuncNoInList(['SYS_SET','SYS_USER','SYS_ICON','SYS_FUNC']).each {
                new SysRoleRela(role: testRole,dataId: it.id,roleType:SysInitData.FUNC_ROLE ).save(flush: true)
            }

            testRole = SysRoles.findByRoleNoAndRoleType(SysInitData.TEST_NAME,SysInitData.DATA_ROLE)

            new SysRoleRela(role: testRole,dataId: SysOrganization.last().id,roleType:SysInitData.DATA_ROLE ).save(flush: true)

        }
    }
}
